package project.web;

import com.alibaba.fastjson.JSON;
import project.pojo.Teacher;
import project.service.TeacherService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/teacherInfoServlet")
public class TeacherInfoServlet extends HttpServlet {
    private TeacherService teacherService = new TeacherService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String teacherId = request.getParameter("teacherId");
        Teacher teacher = teacherService.selectTeacherByTeacherId(Long.parseLong(teacherId));

        String s = JSON.toJSONString(teacher);
        System.out.println(s);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(s);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
